package cn.ithers.blog.controller.portal;

import cn.ithers.blog.service.IImageService;
import cn.ithers.blog.service.impl.ImageServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: zhanghuan
 * @date: 2020/10/13 9:27
 * @description:
 */
@Api(value = "图片", tags = "图片")
@RestController
@RequestMapping("/portal/image")
public class ImagePortalApi {

    @Autowired
    private IImageService iImageService;

    @ApiOperation(value = "获取图片")
    @GetMapping("/{imageUrl}")
    public void getImage(@ApiParam(value = "图片路径",required = true) @PathVariable("imageUrl") String imageUrl, HttpServletResponse response) {
        try {
            iImageService.viewImage(response, imageUrl);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @ApiOperation(value = "获取二维码图片")
    @GetMapping("/qr_code/{code}")
    public void getQrCodeImage(@ApiParam(value = "二维码code",required = true) @PathVariable("code") String code,
                               HttpServletResponse response,
                               HttpServletRequest request) {
        iImageService.createQrCode(code, response, request);
    }
}
